#include <iostream>
using namespace std;

int main()
{
    int f,f1 = 0,f2 = 1;
    int N;
    cin >> N;
    int  left = 0,right = 0;

    while(1)
    {
        f = f1 + f2;
        f1 = f2;
        f2 = f;
        if(f < N)
        {
            left = f;//左边的fib
        }
        else
        {
            right = f;//右边的fib
            break;
        }
    }
    cout << min(N-left,right-N) << endl;
    return 0;
}

